package mylab.base.foundation.orm.ability;

import java.sql.SQLException;
import java.util.Collection;

import cn.hutool.db.Entity;
import cn.hutool.db.sql.Condition;
import mylab.base.foundation.lang.Identifiable;
import mylab.base.foundation.orm.EntityUtil;

public interface Delete<T extends Identifiable<Long>> extends DS, EntityInfo<T> {

    default boolean deleteById(Long id) throws SQLException {
        Entity where = EntityUtil.where(getTableName());
        where.set("id", id);
        return delete(where) == 1;
    }

    default int delete(Collection<Long> ids) throws SQLException {
        Entity where = EntityUtil.where(getTableName());
        where.addCondition(new Condition("id", "in", ids));
        return delete(where);
    }

    default int deleteAll() throws SQLException {
        Entity where = EntityUtil.where(getTableName());
        return delete(where);
    }

    default int delete(Entity where) throws SQLException{
        return getDb().del(where);
    }

}
